export default {
	namespaced: true,
	state: {
		list: []
	},
	mutations:{
		add(state,payload) {
			let good = state.list.find(item => item.goods_id === payload.goods_id)
						
			// 没有=》新增
			if (!good) {
				state.list.push(payload)
			} else {
			  // 有, 直接 数量加一
			  good.goods_count++
			}
		},
		switchSingle(state, {idx, val}){
			
			state.list[idx].goods_checked = val
		},
		changeCount(state, {idx, step}){
			let count = state.list[idx].goods_count;
			// 1. 最大3
			if (step === 1 && count >= 3) {
				return;
			} else if (step === -1 && count === 1) {
				// 2. 最小1
				return;
			}
			// 执行加减操作			
			state.list[idx].goods_count += step
		},
	}
}